import { Column, PrimaryGeneratedColumn, Entity } from 'typeorm'

@Entity('posts')
export class PostsEntity {
  // 标记为主键，值可以自动生成，自增
  @PrimaryGeneratedColumn()
  id: number

  @Column({ comment: '标题', length: 50 })
  title: string

  @Column({ comment: '作者', length: 20 })
  author: string

  @Column({ type: 'text', comment: '内容' })
  content: string

  @Column({ default: '', comment: '缩略图' })
  thumbUrl: string

  @Column({ type: 'tinyint', comment: '分类id' })
  type: number

  @Column({
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP',
    comment: '创建时间'
  })
  createTime: Date

  @Column({
    type: 'timestamp',
    comment: '更新时间',
    default: () => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'
  })
  updateTime: Date
}
